<template>
  <el-container class="layout-container-demo" style="height: 100%">
    <!-- 侧边栏 -->
    <el-aside width="200px">
      <!-- 滚动容器 ，里面的元素，超过了 el-srollerbar的高度，就会自动滚动-->
      <el-scrollbar>
        <!-- menu菜单--导航菜单-开启路由模式--通过index属性=进行路由跳转 -->
        <el-menu
          active-text-color="#ffd04b"
          background-color="#545c64"
          class="el-menu-vertical-demo"
          default-active="2"
          text-color="#fff"
          @open="handleOpen"
          @close="handleClose"
          router
        >
          <MyMenu :arr="userStore.permissionList"></MyMenu>
        </el-menu>
      </el-scrollbar>
    </el-aside>

    <!-- 右侧整体部分 -->
    <el-container>
      <!-- 顶部菜单 -->
      <el-header style="text-align: right; font-size: 12px">
        <div class="toolbar">
          <!-- 下拉菜单 -->
          <el-dropdown>
            <el-icon style="margin-right: 8px; margin-top: 1px">
              <setting />
            </el-icon>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>个人设置</el-dropdown-item>
                <el-dropdown-item @click="$router.push('/login')"
                  >退出</el-dropdown-item
                >
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <span>Tom</span>
        </div>
      </el-header>

      <!-- 右侧主体部分 -->
      <el-main>
        <el-scrollbar>
          <!-- 二级路由的视图出口 -->
          <router-view></router-view>
        </el-scrollbar>
      </el-main>
    </el-container>
  </el-container>
</template>

<script lang="ts" setup>
import { Menu as IconMenu, Location, Setting } from '@element-plus/icons-vue'
import { useUserInfoStore } from '@/stores/user'
// MyMenu 引入自定义的组件--自动注册
import MyMenu from '@/components/MyMenu.vue'

const userStore = useUserInfoStore()
// 可以根据路由信息，生成menu菜单--动态菜单
userStore.permissionList

const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
</script>

<style scoped>
.layout-container-demo .el-header {
  position: relative;
  background-color: var(--el-color-primary-light-7);
  color: var(--el-text-color-primary);
}
.layout-container-demo .el-aside {
  color: var(--el-text-color-primary);
  background: var(--el-color-primary-light-8);
  background-color: #545c64;
}
.layout-container-demo .el-menu {
  border-right: none;
}
.layout-container-demo .el-main {
  padding: 0;
}
.layout-container-demo .toolbar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  right: 20px;
}
</style>
